﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DTO;
using DAO;
using System.Data.SqlClient;

namespace DAO
{
    public class DAO_NguyenNhanMat
    {
        DataServices data = new DataServices();
        public DataTable GetNguyenNhanMat()
        {
            string query = "Select * From "+ DTO_NguyenNhanMat.TableName;
            return data.executeGetDataTable(query);
        }
        public bool InsertNguyenNhanMat(DTO_NguyenNhanMat dto)
        {
            bool bKQ = false;
            try
            {
                string query = "Insert into " + DTO_NguyenNhanMat.TableName + "(" + DTO_NguyenNhanMat.TENNGUYENNHAN +
                                                                                      ") Values(@" + DTO_NguyenNhanMat.TENNGUYENNHAN + ")";
                SqlParameter para = new SqlParameter(DTO_NguyenNhanMat.TENNGUYENNHAN, dto.TenNguyenNhan);
                bKQ = data.executeUpdate(query, para);
            }
            catch (Exception ex)
            {
                
                throw new Exception(ex.Message,ex);
            }
            return bKQ;
        }
        public bool UpdateNguyenNhanMat(DTO_NguyenNhanMat dto)
        {
            bool bKQ = false;
            try
            {
                string query = "UPDATE " + DTO_NguyenNhanMat.TableName + " SET " + DTO_NguyenNhanMat.TENNGUYENNHAN + " =@" + DTO_NguyenNhanMat.TENNGUYENNHAN
                                                                          + " Where " + DTO_NguyenNhanMat.MANGUYENNHAN + " =@" + DTO_NguyenNhanMat.MANGUYENNHAN;
                SqlParameter para1 = new SqlParameter(DTO_NguyenNhanMat.TENNGUYENNHAN, dto.TenNguyenNhan);
                SqlParameter para2 = new SqlParameter(DTO_NguyenNhanMat.MANGUYENNHAN, dto.MaNguyenNhan);
                bKQ = data.executeUpdate(query, para1, para2);
            }
            catch (Exception ex)
            {
                 throw new Exception(ex.Message,ex);
            }
            return bKQ;
        }
        public bool DeleteNguyenNhanMat(DTO_NguyenNhanMat dto)
        {
            bool bKQ = false;
            try
            {
                string query = "deleteNguyenNhanMat";
                SqlParameter para = new SqlParameter(DTO_NguyenNhanMat.MANGUYENNHAN, dto.MaNguyenNhan);
                bKQ = data.updateFormProcedure(query, para);
            }
            catch (Exception ex)
            {

                throw new Exception(ex.Message,ex);
            }
            return bKQ;
        }
        public DataTable GetNguyenNhanMatByName(string name)
        {
            try
            {
                string query = "Select * From " + DTO_NguyenNhanMat.TableName + " Where " + DTO_NguyenNhanMat.TENNGUYENNHAN + " LIKE @" + DTO_NguyenNhanMat.TENNGUYENNHAN;
                SqlParameter para = new SqlParameter(DTO_NguyenNhanMat.TENNGUYENNHAN, "%" + name + "%");
                return data.executeGetDataTable(query, para);
            }
            catch (Exception ex)
            {
                
                throw new Exception(ex.Message,ex);
            }
        }
    }
}

